
class MyBlockingQueue {
    private String[] data = null;
    private int head = 0;
    private int tail = 0;
    private int size = 0;

    private Object locker = new Object();

    public MyBlockingQueue(int capacity) {
        data = new String[capacity];
    }

    public void put(String s ) throws InterruptedException {
        synchronized (this) {

            if (size == data.length) {
                //队列满了
               // return;
                this.wait();
            }
            data[tail] = s;
            tail++;
            if (tail >= data.length) {
                tail = 0;
            }
            size++;
            this.notify();
        }
    }

    public String take() throws InterruptedException{
        String ret="";
        synchronized (this) {
            if (size == 0) {
                //队列为空
               // return null;
                this.wait();
            }
            ret = data[head];
            head++;
            if (head >= data.length) {
                head = 0;
            }
            size--;
            return ret;
        }
    }
}
public class Demo3 {
    public static void main(String[] args) {

    }
}
